﻿using System;
using NUnit.Framework;

namespace cshape_demo
{
    [TestFixture]
    public class NewOneClass
    {
        [Test]
        public void TestCreateInstance()
        {
            OneClass oneClass = new OneClass();
            oneClass.id = 12;
            oneClass.name = "s12";
            Console.WriteLine(oneClass);
        }

        [Test]
        public void TestCreateInstance2()
        {
            TwoClass twoClass = new TwoClass();
            twoClass.Id = 12;
            twoClass.Name = "s12";
            Console.WriteLine("{0}, {1}", twoClass.Id, twoClass.Name);
        }

        [Test]
        public void TestStaticAttribute()
        {
            OneClass oneClass = new OneClass();
            oneClass.Count();
            oneClass.Count();
            oneClass.Count();

            Console.WriteLine(OneClass.GetCounter());
        }
    }

    /**
     * 说明:
     * 1. 类的 析构函数 是类的一个特殊的成员函数，当类的对象超出范围时执行。
     * 2. 析构函数的名称是在类的名称前加上一个波浪形（~）作为前缀，它不返回值，也不带任何参数。
     * 3. 析构函数用于在结束程序（比如关闭文件、释放内存等）之前释放资源。析构函数不能继承或重载。
     */
    public class OneClass
    {
        public int id;

        public String name;

        public static int counter = 0;

        public void Count()
        {
            OneClass.counter++;
        }

        public static int GetCounter()
        {
            return OneClass.counter;
        }

        ~OneClass()
        {
            Console.WriteLine("该对象删除了");
        }

        public override string ToString()
        {
            return this.id + " " + this.name;
        }
    }

    /**
     * 说明:
     * 1. 将属性封装, 但是感觉这么做没有必要.
     */
    public class TwoClass
    {
        private int _id;

        private String _name;
        
        public int Id
        {
            get => this._id;
            set
            {
                if (value > 10)
                {
                    this._id = 0;
                }
                else
                {
                    this._id = value;
                }
            }
        }

        public String Name
        {
            get => this._name;
            set => this._name = value;
        }
        
        
    }
}